<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="org.jadestudio.dsdown.entity.ManageGamePublishCompany" %>
<%@ page import="org.jadestudio.dsdown.util.SysInfo" %>
<%@ page import="java.util.*" %>
<%
				String mode=(String)request.getAttribute("flag");
				String url="";
				String title="";
				if(mode!=null && !mode.equals("")){
					if(mode.equals("add")){
						title="文章新增";
						url="articleManage.do?pm=articleAdd";
					}else if(mode.equals("modify")){
						title="文章修改";
						url="articleManage.do?pm=articleModify";
					}
				}
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form action="" method="post" name="articleForm" id="articleForm">
<input type="hidden" name="article_id" value='${articleMap.article_id}'>
<input type="hidden" name="article_content" id="article_content" value='${articleMap.article_content}'>
<script type="text/javascript" src="/resources/xheditor-1.1.13/xheditor-1.1.14-zh-cn.min.js"></script>
<script type="text/javascript">
		var editor;
		$(document).ready(function(){
			//初始化xhEditor编辑器插件
			editor=$('#xh_editor').xheditor({
				disableContextmenu:false,
				tools:'full',
				skin:'default',
				upMultiple:true,
				html5Upload:false,
				upImgUrl: "common.do?pm=imgUpload2",
				forcePtag:true,
				upImgExt: "jpg,jpeg,gif,bmp,png",
				width:800,
				height:500,
				//onUpload:insertUpload,
				//html5Upload:false,
				forcePtag:false,
				internalScript:true,
				inlineScript:true,
				//linkTag:true
				localUrlTest:/^https?:\/\/[^\/]*?(<%=SysInfo.remotePicSavedHost%>)\//i,
				remoteImgSaveUrl:"common.do?pm=imgUpload3"
			});
			
			//xbhEditor编辑器图片上传回调函数
			function insertUpload(msg) {
				
			}
			//处理服务器返回到回调函数的字符串内容,格式是JSON的数据格式.
			function Substring(s){
				return s.substring(s.substring(0,s.lastIndexOf("/")).lastIndexOf("/"),s.length);
			}
			
				/*文章名称失去焦点时的关键字获取*/
				$("#article_name").blur(function(){
					$.post("articleManage.do?pm=getArticleKeyWord","articleTitle="+$("#article_name").val(),function(keyword){
						$("#article_keyword").val(keyword);
					})
				});
				
				
			$('#xh_editor').val('${articleMap.article_content}') ;
		});
function readyToSubmit(){
	document.getElementById("articleForm").action="<%=url%>";
	var article_content_value = editor.getSource();
	$("#article_content").val(article_content_value);
	//TODO:需要验证下参数
	document.getElementById("articleForm").submit();
}
function deleteGameIdUrl(obj) {
		$(obj).parent().parent().next().remove();
		$(obj).parent().parent().remove();
	}
	
	
function bandautoComplete(obj){
				/***************autocomplete加载	******************/
				$(obj).autocomplete(
						"articleManage.do?pm=getGameByName", {
							minChars : 1,
							max : 20,
							autoFill : false,
							scroll : true,
							mustMatch : false,
							matchContains : true,
							scrollHeight : 220,
							dataType : 'json',
							matchSubset : false,
							cacheLength : 0,
							parse : function(data) {
								if (data != "") {
									data = eval(data);//去空格;
							var rows = [];
							for ( var i = 0; i < data.length; i++) {
								rows[i] = {
									data : data[i].name, //下拉框显示数据格式   
									value : data[i].id, //选定后实际数据格式   
									result : data[i].name
								//选定后输入框显示数据格式   
								};
							}
							return rows;
						}
					},
					formatItem : function(data, i, total) {
						return data;
					}
					}).result(function(event, item, obj1) {
					if (item == "" || item == "SESSION丢失" || item == "不存在的数据") {
						$(obj).next().val("");
						$(obj).val("");
					} else {
						$(obj).next().val(obj1);
					}
				});
				/***************autocomplete加载END	******************/
}

function unbandautoComplete(obj){
	$(obj).unbind("autocomplete");
}

function addGameIdUrl() {
		var game_Ids = "<tr><td colspan='2'><input autocomplete='off' type='text' name='game_id' id='game_id' size='40' onfocus='bandautoComplete(this)' onblur='unbandautoComplete(this)'  maxlength='200' /><input type='hidden' style='display: none' name='game_id_value' id='game_id_value' value='' size='24' maxlength='32' />&nbsp;<input style='border:1px #333 solid' onclick='deleteGameIdUrl(this)'  value='删除' type='button' /></td></tr><tr><td colspan='3'>&nbsp;</td></tr>";
		var game_Ids_Content = $("#game_ids_div").html() + game_Ids;
		$("#game_ids_div").html(game_Ids_Content);
	}
	
function appendWriterHtml(){
	editor.appendHTML('[page=标题]<br/><span style=color:c0c0c0>put your content here!</span><br/>');
}
</script>
<!-- autoComplete加载 -->
<script language="javascript"
	src="/resources/scripts/jquery.autocomplete.js">
</script>
<style type="text/css">
.ac_results {
	padding: 0px;
	border: 1px solid black;
	background-color: white;
	overflow: hidden;
	z-index: 99999;
}

.ac_results ul {
	width: 100%;
	list-style-position: outside;
	list-style: none;
	padding: 0;
	margin: 0;
}

.ac_results li {
	margin: 0px;
	padding: 2px 5px;
	cursor: default;
	display: block;
	font: menu;
	font-size: 12px;
	line-height: 16px;
	overflow: hidden;
}

.ac_loading {
	background: white url('indicator.gif') right center no-repeat;
}

.ac_odd {
	background-color: #eee;
}

.ac_over {
	background-color: #CCC;
	color: black;
}
</style>
<!-- autoComplete加载 END-->
<style type="text/css">
input {
	border: 1px #ccc solid;
}
</style>
<div class="content-box-header">
					<h3><%=title %></h3>
					<div class="clear"></div>
				</div> 
                <div class="content-box-content">
               	  	<table>
               	  		<thead>
                  			<tr>
                  				<td style="width:70px">文章名称 &nbsp;</td>
                  				<td style="width:280px"><input checkSelf="true" type="text" name="article_name" id="article_name" value="${articleMap.article_name}" size="40" maxlength="200"></td>
                  				<td checkSelfNotice="true"></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px">关联游戏 &nbsp;</td>
                  				<td colspan="2"><input type="button" name="game_add_button" id="game_add_button"  onclick="addGameIdUrl()" style="border:solid 1px #333"  value="新增">&nbsp;&nbsp;<span style='color:red'>先新增好再逐个赋值，不要新增一个赋值一个，不然会有问题！</span></td>
                  			</tr>
                  			<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
                  			<tr>
                  				<td colspan="1"></td>
                  				<td id="game_ids_div" colspan="3">
                  					<% 
                  					List<Map> gameArticleList=(List<Map>)request.getAttribute("gameArticleList"); 
                  					if(gameArticleList!=null && gameArticleList.size()>0){
                  						for(int t=0;t<gameArticleList.size();t++){
                  					%>
                  						<tr>
                  							<td colspan="1"></td>
                  							<td colspan='2'><input autocomplete='off' type='text' name='game_id' id='game_id' size='40' onfocus='bandautoComplete(this)' onblur='unbandautoComplete(this)'  maxlength='200' value='<%=gameArticleList.get(t).get("simplified_chinese_name") %>' /><input type='hidden' style='display: none' name='game_id_value' id='game_id_value' value='<%=gameArticleList.get(t).get("game_id") %>' size='24' maxlength='32' />&nbsp;<input style='border:1px #333 solid' onclick='deleteGameIdUrl(this)'  value='删除' type='button' /></td>
                  						</tr>
                  						<tr>
                  							<td colspan='3'>&nbsp;</td>
                  						</tr>
                  					<%
                  						}
                  					}
                  					%>
                  				</td>
                  			</tr>
                  			<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
                  			<tr>
                  				<td>类型&nbsp; </td>
                  				<td><select  name="article_type" value="${articleMap.article_type}">
                  					<option value="1" ${articleMap.article_type eq '1'?'selected':''} >攻略</option>
                  					<option value="2" ${articleMap.article_type eq '2'?'selected':''} >资讯</option>
                  					<option value="3" ${articleMap.article_type eq '3'?'selected':''} >发售表</option>
                  					<option value="4" ${articleMap.article_type eq '4'?'selected':''} >推广</option>
                  				</select></td>
                  				<td></td>
                  			</tr>
                  			<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px">TAG &nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_tag" value="${articleMap.article_tag}" size="40" maxlength="100"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px">文章关键字&nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_keyword" id="article_keyword" value="${articleMap.article_keyword}" size="40" maxlength="100"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px">作者&nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_writer" value="${articleMap.article_writer}" size="40" maxlength="200"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px">文章简介&nbsp;</td>
                  				<td style="width:280px"><textarea name="article_description" rows="6"  cols="20">${articleMap.article_description}</textarea></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <% 
		                    	if(mode.equals("modify")){
		                    %>
		                    <tr>
                  				<td style="width:70px">点击数&nbsp;</td>
                  				<td style="width:280px"><input name="article_click" size="8" value="${articleMap.article_click}"/></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <%} %>
		                    
		                     <tr>
                  				<td colspan="1"><input type="button" value="增加一页" onclick="appendWriterHtml()" style="border:solid 1px #000;width:100px;cursor:pointer;height:40px;margin-top:10px" onmousemove=(this.style.background='#57a000') onmouseout=(this.style.background='#FFF') /></td>
                  				<td colspan="2">&nbsp;&nbsp;<input type="button" value="清空内容" onclick="if(confirm('一旦清空则不可恢复，确认？')){$('#xh_editor').val('')}" style="border:solid 1px #000;width:100px;cursor:pointer;height:40px;margin-top:10px" onmousemove=(this.style.background='#57a000') onmouseout=(this.style.background='#FFF') /></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
                  				<td style="width:70px" colspan="4"><textarea id="xh_editor" name="article_content_obj" rows="25" style="width:100%;height:100%; border: 1px"></textarea></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
								<td style="width: 70px">
									是否转载 &nbsp;
								</td>
								<td style="width: 280px">
									<select type="text" name="article_isreship">
										<option value="0" ${articleMap.article_isreship eq "0" ? "selected" : ""}>
											否
										</option>
										<option value="1" ${articleMap.article_isreship eq "1" ? "selected" : ""}>
											是
										</option>
									</select>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<td colspan="3">
									&nbsp;
								</td>
							</tr>
				
                  			<tr>
                  				<td style="width:70px">转载地址&nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_reship_url" value="${articleMap.article_reship_url}" size="40" maxlength="200"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    
		                   <tr>
								<td style="width: 70px">
									是否跳转 &nbsp;
								</td>
								<td style="width: 280px">
									<select type="text" name="article_is_redirect">
										<option value="0" ${articleMap.article_is_redirect eq "0" ? "selected" : ""}>
											否
										</option>
										<option value="1" ${articleMap.article_is_redirect eq "1" ? "selected" : ""}>
											是
										</option>
									</select>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<td colspan="3">
									&nbsp;
								</td>
							</tr>
		                  	<tr>
                  				<td style="width:70px">跳转地址&nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_redirect_url" value="${articleMap.article_redirect_url}" size="40" maxlength="200"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
		                    <tr>
								<td style="width: 70px">
									是否置顶 &nbsp;
								</td>
								<td style="width: 280px">
									<select type="text" name="article_position_top">
										<option value="0" ${articleMap.article_position_top eq "0" ? "selected" : ""}>
											否
										</option>
										<option value="1" ${articleMap.article_position_top eq "1" ? "selected" : ""}>
											是
										</option>
									</select>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<td colspan="3">
									&nbsp;
								</td>
							</tr>
							 <tr>
								<td style="width: 70px">
									是否开启 &nbsp;
								</td>
								<td style="width: 280px">
									<select type="text" name="article_enable">
										<option value="1" ${articleMap.article_enable eq "1" ? "selected" : ""}>
											是
										</option>
										<option value="0" ${articleMap.article_enable eq "0" ? "selected" : ""}>
											否
										</option> 
									</select>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<td colspan="3">
									&nbsp;
								</td>
							</tr>
							<tr>
                  				<td style="width:70px">文章索引&nbsp;</td>
                  				<td style="width:280px"><input  type="text" name="article_search_index" value="${articleMap.article_search_index}" size="4" maxlength="4"></td>
                  				<td ></td>
                  			</tr>
	                 		<tr>
		                   		<td colspan="3">&nbsp;</td>
		                    </tr>
							
                  			<tr>
                  			   <td style="text-align: right"><input style="border:solid 1px #CCC;width:100px;" onmousemove=(this.style.background='#57a000') onmouseout=(this.style.background='#FFF') type="button" onclick="readyToSubmit()" value="提交"/></td>
                  			   <td style="text-align: center"><input style="border:solid 1px #CCC;width:100px;" onmousemove=(this.style.background='#57a000') onmouseout=(this.style.background='#FFF') onclick="location.href='articleManage.do?pm=gotoArticleList'" type="button" value="后退"/></td>
		                  	   <td colspan="2"></td>
		                   </tr>
                  		</thead>
                  	</table>
                </div>
</form>            